/**
 * My simple header template from child directory
 * Direction.java - ${projectName} - ${organizationName} - ${inceptionYear}
 */
package FourthTry;

/*
 * #%L
 * Ability-tester
 * %%
 * Copyright (C) 2014 AmazingSERKU
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */


/**
 * Created with IntelliJ IDEA.
 * User: Gauss
 * Date: 23.12.13
 * Time: 22:04
 * To change this template use File | Settings | File Templates.
 */
public enum Direction {
    UP {
        @Override
        public void changeCoordinate(Coordinates coordinates) {
            coordinates.decrementX();
        }

        @Override
        public Direction opposite() {
            return DOWN;
        }

        @Override
        public Direction clockWise() {
            return RIGHT;
        }

        @Override
        public Direction counterClockWise() {
            return LEFT;
        }

        @Override
        public void decreaseMeasures(Coordinates measuresFrom, Coordinates measuresTo) {
            changeCoordinate(measuresTo);
        }

        @Override
        public void decreaseMeasures(Coordinates measuresFrom, Coordinates measuresTo, Coordinates currentCoordinates) {
            measuresFrom.x = currentCoordinates.x;
        }
    }, DOWN {
        @Override
        public void changeCoordinate(Coordinates coordinates) {
            coordinates.incrementX();
        }

        @Override
        public Direction opposite() {
            return UP;
        }

        @Override
        public Direction clockWise() {
            return LEFT;
        }

        @Override
        public Direction counterClockWise() {
            return RIGHT;
        }

        @Override
        public void decreaseMeasures(Coordinates measuresFrom, Coordinates measuresTo) {
            changeCoordinate(measuresFrom);
        }

        @Override
        public void decreaseMeasures(Coordinates measuresFrom, Coordinates measuresTo, Coordinates currentCoordinates) {
            measuresTo.x = currentCoordinates.x;
        }
    }, LEFT {
        @Override
        public void changeCoordinate(Coordinates coordinates) {
            coordinates.decrementY();
        }

        @Override
        public Direction opposite() {
            return RIGHT;
        }

        @Override
        public Direction clockWise() {
            return UP;
        }

        @Override
        public Direction counterClockWise() {
            return DOWN;
        }

        @Override
        public void decreaseMeasures(Coordinates measuresFrom, Coordinates measuresTo) {
            changeCoordinate(measuresTo);
        }

        @Override
        public void decreaseMeasures(Coordinates measuresFrom, Coordinates measuresTo, Coordinates currentCoordinates) {
            measuresFrom.y = currentCoordinates.y;
        }
    }, RIGHT {
        @Override
        public void changeCoordinate(Coordinates coordinates) {
            coordinates.incrementY();
        }

        @Override
        public Direction opposite() {
            return LEFT;
        }

        @Override
        public Direction clockWise() {
            return DOWN;
        }

        @Override
        public Direction counterClockWise() {
            return UP;
        }

        @Override
        public void decreaseMeasures(Coordinates measuresFrom, Coordinates measuresTo) {
            changeCoordinate(measuresFrom);
        }

        @Override
        public void decreaseMeasures(Coordinates measuresFrom, Coordinates measuresTo, Coordinates currentCoordinates) {
            measuresTo.y = currentCoordinates.y;
        }
    };
    public abstract void changeCoordinate(Coordinates coordinates);
    public abstract Direction opposite();
    public abstract Direction clockWise();
    public abstract Direction counterClockWise();
    public abstract void decreaseMeasures(Coordinates measuresFrom, Coordinates measuresTo);
    public abstract void decreaseMeasures(Coordinates measuresFrom, Coordinates measuresTo, Coordinates currentCoordinates);

    public static Direction calculateDirection(Coordinates startCoordinates, Coordinates endCoordinates) {
        if (startCoordinates.getX()==endCoordinates.getX()) {
            if (startCoordinates.getY() < endCoordinates.getY()) {
                return RIGHT;
            }
            else {
                return LEFT;
            }
        }
        if (startCoordinates.getY()==endCoordinates.getY()) {
            if (startCoordinates.getX() < endCoordinates.getX()) {
                return DOWN;
            }
            else {
                return UP;
            }
        }
        return null;
    }
}
